package com.bll.tsdoa.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bll.tsdoa.entity.Part;
import com.bll.tsdoa.mapper.PartDao;
import com.bll.tsdoa.service.PartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 零件(Part)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 00:04:41
 */
@Service("partService")
@Slf4j
public class PartServiceImpl extends ServiceImpl<PartDao, Part> implements PartService {
    @Resource
    private PartDao partDao;

    @Override
    public boolean add(Part part) {
        try {
            if (log.isInfoEnabled()) {
                log.info("PartController.add.entity::{}", JSON.toJSONString(part));
            }
            int result = partDao.insert(part);
            return result > 0;
        } catch (Exception e) {
            log.error(e.getMessage());
            return false;
        }
    }

    @Override
    public boolean delete(Part part) {
        try {
            if (log.isInfoEnabled()) {
                log.info("PartController.delete.entity::{}", JSON.toJSONString(part));
            }
            int result = partDao.deleteById(part.getId());
            return result > 0;
        } catch (Exception e) {
            log.error(e.getMessage());
            return false;
        }
    }
}

